﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CarExam.DAL;
using CarExam.Common;
using CarExam.Model;
using System.Data;

namespace CarExam.BLL
{
    public class UserBLL
    {
        UserDAL _userdal = new UserDAL();

        /// <summary>
        /// 登录
        /// </summary>
        /// <returns>0:成功 1:失败</returns>
        public int UserLogin(string account, string password,out UserInfo _ui)
        {
            _ui = new UserInfo();

            DataTable dt = null; int res = -1;
            if (!string.IsNullOrEmpty(account) && !string.IsNullOrEmpty(password))
            {
                res = _userdal.UserLogin(account, password, out dt);
                if (dt != null && dt.Rows.Count > 0)
                {
                    _ui.Uid = int.Parse(dt.Rows[0]["UID"].ToString());
                    _ui.Account = account;
                    _ui.Realname = dt.Rows[0]["realname"].ToString();
                }
            }
            return res;
        }

        /// <summary>
        /// 退出登录时更新锁定登录状态值
        /// </summary>
        public bool UpdateIsLocked(int uid)
        {
            if (uid > 0)
                return _userdal.UpdateIsLocked(uid);
            return false;
        }
    }
}
